/*
 * Mouse.cpp
 *
 * Copyright (c) 2009-2011 [BRN] aka. SWW13.
 *
 * This file is part of [BRN]Lib.
 *
 * [BRN]Lib is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * [BRN]Lib is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with [BRN]Lib.  If not, see <http ://www.gnu.org/licenses/>.
 */

#include "Mouse.h"

namespace BRNlib
{
	namespace Core
	{
		POINT Mouse::GetPos()
		{
			POINT MousePos;
			GetCursorPos(&MousePos);

			if(Core::Window::GetWindow() != NULL)
				ScreenToClient(Core::Window::GetWindow(), &MousePos);

			return MousePos;
		}
		bool Mouse::IsLeftDown()
		{
			return (GetAsyncKeyState(VK_LBUTTON) != 0);
		}
		bool Mouse::IsRightDown()
		{
			return (GetAsyncKeyState(VK_RBUTTON) != 0);
		}

		bool Mouse::IsInRect(RECT Rect)
		{
			POINT Pos = GetPos();
			
			return (Pos.x > Rect.left && Pos.x < Rect.right) && (Pos.y > Rect.top && Pos.y < Rect.bottom);
		}

		bool Mouse::IsLeftClicked()
		{
			if(!LeftMouse && IsLeftDown())
			{
				LeftMouse = true;
				return true;
			}
			else if(LeftMouse && !IsLeftDown())
				LeftMouse = false;

			return false;
		}
		bool Mouse::IsRightClicked()
		{
			if(!RightMouse && IsRightDown())
			{
				RightMouse = true;
				return true;
			}
			else if(RightMouse && !IsRightDown())
				RightMouse = false;

			return false;
		}
	}
}